package com.aegis.manage.controller.sys;

import com.aegis.common.mybatis.base.BaseController;
import com.aegis.common.mybatis.model.PageResult;
import com.aegis.manage.api.request.CreateUserRequest;
import com.aegis.manage.api.vo.SysUserVO;
import com.aegis.manage.api.vo.UserDetailVO;
import com.aegis.manage.model.dos.SysUser;
import com.aegis.manage.service.sys.role.SysRoleService;
import com.aegis.manage.service.sys.user.SysUserService;
import com.aegis.manage.utils.AuthUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * @Author renogo
 *
 * @Version 1.0
 * @Descritube
 */
@RestController
@RequestMapping("/sys/user")
@Api(tags = "系统-用户管理")
public class SysUserController extends BaseController<SysUserService> {

    @Autowired
    private SysRoleService sysRoleService;




    @ApiOperation(value = "查询用户分页", notes = "查询用户分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页码", required = false),
            @ApiImplicitParam(name = "size", value = "每页数据量", required = false),
            @ApiImplicitParam(name = "keywords", value = "检索关键词", required = false),
    })
    @GetMapping("/page")
    public PageResult<SysUserVO> selectUserPage(@RequestParam(required = false, defaultValue = "1") int current,
                                                @RequestParam(required = false, defaultValue = "10") int size,
                                                @RequestParam(required = false) String keywords) {
        return getService().selectUserPage(current, size, keywords);
    }

    @ApiOperation(value = "添加用户", notes = "添加用户")
    @PostMapping("/add")
    public String createUser(@RequestBody @Validated CreateUserRequest createUserRequest) {
        return getService().createUser(createUserRequest);
    }

    @ApiOperation(value = "删除用户", notes = "删除用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = false),
    })
    @DeleteMapping("/del")
    public void delUser(@RequestParam("id") String id) {
        getService().delUser(id);
    }


    @ApiOperation(value = "用户绑定角色", notes = "用户绑定角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = false),
    })
    @PostMapping("/bindRole")
    public void bindUserRole(@PathVariable("id") String userId, @RequestBody Set<String> roleIds) {
        getService().bindUserRole(userId, roleIds);
    }




}
